import r from './axios'
import qs from 'qs'

/**
 * 登录
 * @param data
 */
export function login(data: any) {
    return r.post('/api/user/login', data)
}

/**
 * 找回密码
 * @param data
 */
export function forgt(data: any) {
    return r.post('/api/user/forget', data)
}

/**
 * 注册
 * @param data
 */
export function regrpt(data: any) {
    data['role'] = 'USER'
    return r.post('/api/user/register', data)
}

/**
 * 获取验证码
 * @param req
 */
export function getC(req: any) {
    req['codeType'] = 'email'
    return r.get('/api/user/code', {params: req})
}

/**
 * 获取猜你喜欢
 */
export function guess() {
    return r.get('/api/usr/index/guess')
}

/**
 * 获取鲜花咨询
 */
export function arle(params: any) {
    return r.get('/api/usr/article', {params})
}

/**
 * 获取鲜花详情
 */
export function floDetail(productId: string) {
    return r.get(`/api/usr/index/product/detail/${productId}`)
}

/**
 * 获取当前用户信息
 */
export function getUserInfo() {
    return r.get('/api/user')
}

/**
 * 支付
 */
export function puty(preOrderType: 'buyNow' | 'shoppingCart' | null | string, orderDetails: {
    shoppingCartId: "" | null;
    productId: "" | null;
    quantity: any
}[]) {
    preOrderType = sessionStorage.getItem('preOrderType')
    let data = {preOrderType, orderDetails}
    return r.post('/api/usr/order/payOrder', JSON.stringify(data), {
        paramsSerializer: function (params) {
            return qs.stringify(params, {arrayFormat: 'repeat'})
        },
        headers: {
            'Content-Type': 'application/json',
            puy: 'true'
        }
    })
}

/**
 * 获取鲜花列表
 */
export function getFloList(par: any) {
    return r.get('/api/usr/index/product', {params: par})
}

/**
 * 获取鲜花资讯
 * @param par
 */
export function getAce(par: any) {
    return r.get('/api/usr/article', {params: par})
}

/**
 * 文章详情
 */
export function getAceDetail(articleId: any) {
    return r.get(`/api/usr/article/${articleId}`)
}

/**
 * 获取我的收藏
 */
export function getCollet(data: any) {
    return r.get('/api/usr/collect', {params: data})
}

export function upUser(data: any) {
    return r.put('/api/user', data)
}

export function upP(data: any) {
    return r.post('/api/user/reset', data)
}

/**
 * 获取购物车列表
 */
export function getusrCat() {
    return r.get('/api/usr/cart', {params: {page: 1, size: 999999}})
}

/**
 * 删除购物车
 */
export function deleteUsrCat(id: any) {
    return r.delete('/api/usr/cart', {
        params: {ids: [id]},
        paramsSerializer: function (params) {
            return qs.stringify(params, {arrayFormat: 'repeat'})
        }
    })
}

/**
 * 添加或更新购物车
 */
export function potUsrCat(productId: any, productNum: any) {
    return r.post('/api/usr/cart', {productId, productNum})
}

/**
 * 直接修改购物车数量
 */
export function putUsrCat(productId: any, num: any) {
    return r.put(`/api/usr/cart/direct/update/${productId}`, {productId, num})
}

/**
 * 添加收藏
 * @param productId
 */
export function pstClooct(productId: any) {
    return r.post('/api/usr/collect', {productId})
}

/**
 * 取消收藏
 * @param id
 */
export function deleteClooct(id: any) {
    return r.delete(`/api/usr/collect/${id}`)
}

/**
 * 我的订单
 * @param par
 */
export function getOrderL(par: any) {
    return r.get('/api/usr/order/list', {params: par})
}

/**
 * 订单详情
 */
export function getOrderDe(orderId: any) {
    return r.get(`/api/usr/order/info/${orderId}`)
}

/**
 * 收货
 * @param orderId
 */
export function orderTake(orderId: any) {
    return r.get(`/api/usr/order/take/${orderId}`)
}

export function orRef(orderId: any) {
    return r.post('/api/usr/order/refund', {orderId})
}

export function chatSendApi(data: any) {
    return r.post('/api/chat/send', data)
}






















